<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random</title>
    <script>
        //Math.random: 返回一个随机小数 x 属于 [0,1)
        console.log(Math.random());
        //我们想要得到两个数之间的随机整数
        // Math.floor(Math.random()*(max - min + 1)+min)
        function getRandom(max, min) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        }
        console.log(getRandom(1, 10));

        //随机点名
        var arr = ['张三', '张三丰', '李四', '王五'];
        console.log(arr[Math.floor(Math.random() * arr.length)]);//[0,4)向下取整:[0,1,2,3]
    </script>
</head>

<body>

</body>

</html>